package com.easyfun.healthmagicbox.bluetooth.enbp;

import com.easyfun.healthmagicbox.bluetooth.BTMessage;

public class EnBloodPressureMessage extends BTMessage<EnBloodPressureMsgType>{
	@Override
	public EnBloodPressureMsgType getMsgType()
	{
		if (rawBytes.length == 1)
		{
			return EnBloodPressureMsgType.START;
		}
		
		if (rawBytes.length > 4)
		{
			if (rawBytes[2] == EnBloodPressureMsgType.CONNECTED.getIndentify())
			{
				return EnBloodPressureMsgType.CONNECTED;
			}
			if (rawBytes[2] == EnBloodPressureMsgType.SENDING.getIndentify())
			{
				return EnBloodPressureMsgType.SENDING;
			}
			if (rawBytes[2] == EnBloodPressureMsgType.SUCCESSFULRESULT.getIndentify())
			{
				return EnBloodPressureMsgType.SUCCESSFULRESULT;
			}
			if (rawBytes[2] == EnBloodPressureMsgType.ERRORRESULT.getIndentify())
			{
				return EnBloodPressureMsgType.ERRORRESULT;
			}
			if (rawBytes[2] == EnBloodPressureMsgType.CLOSED.getIndentify())
			{
				return EnBloodPressureMsgType.CLOSED;
			}
		}
		return EnBloodPressureMsgType.NONE;
	}

	String highPressure;
	String lowPressure;
	String runningHighPressure;
	String runningLowPressure;
	String heartRate;
	String errorCode;
	public void fillin() {
		// TODO Auto-generated method stub
		
	}
	protected String getErrorCode() {
		if (getMsgType() == EnBloodPressureMsgType.ERRORRESULT)
		{
			errorCode = Byte.valueOf(rawBytes[3]).toString();
		}
		return errorCode;
	}

	protected String getRunningHighPressure() {
		if (getMsgType() == EnBloodPressureMsgType.SENDING)
		{
			runningHighPressure = String.valueOf((rawBytes[3]&0xff));
		}
		return runningHighPressure;
	}

	protected String getRunningLowPressure() {
		if (getMsgType() == EnBloodPressureMsgType.SENDING)
		{
			runningLowPressure = String.valueOf(rawBytes[4]&0xff);
		}
		return runningLowPressure;
	}
	protected String getHighPressure() {
		if (getMsgType() == EnBloodPressureMsgType.SUCCESSFULRESULT)
		{
			//because the pressure is unsigned char
			highPressure = String.valueOf(rawBytes[3]&0xff).toString();
		}
		return highPressure;
	}
	
	protected String getLowPressure() {
		if (getMsgType() == EnBloodPressureMsgType.SUCCESSFULRESULT)
		{
			lowPressure = String.valueOf(rawBytes[4]&0xff).toString();
		}
		return lowPressure;
	}
	
	protected String getHeartRate() {
		if (getMsgType() == EnBloodPressureMsgType.SUCCESSFULRESULT)
		{
			heartRate = String.valueOf(rawBytes[5]&0xff).toString();
		}
		return heartRate;
	}
	

}
